Delete file function

James Peret 8 years ago
parent
commit
dcfe357b74
3 changed files with 25 additions and 1 deletions
  1. 14 0
      app/scripts/controllers/app-ctrl.js
  2. 11 0
      app/scripts/services/file-service.js
  3. 0 1
      codex/inbox/hgvhgc.md

+ 14 - 0
app/scripts/controllers/app-ctrl.js

@@ -147,6 +147,20 @@ angular.module('codexApp.index', [])
147 147
         console.log("-> Copying URL to clipboard " + url);
148 148
         clipboard.writeText(url);
149 149
       } }));
150
+      menu.append(new MenuItem({ label: 'Delete', click: function () {
151
+        if(FileService.deleteFile(file.path)){
152
+          var index = $scope.files.indexOf(file);
153
+          if (index > -1) {
154
+            if(!$scope.$$phase) {
155
+              $scope.$apply(function(){
156
+                $scope.files.splice(index, 1);
157
+              });
158
+            } else {
159
+                $scope.files.splice(index, 1);
160
+            }
161
+          }
162
+        };
163
+      } }));
150 164
       menu.popup(currentWindow);
151 165
     }
152 166
 

+ 11 - 0
app/scripts/services/file-service.js

@@ -392,6 +392,13 @@ angular.module('codexApp')
392 392
     return filtered;
393 393
   }
394 394
 
395
+  var deleteFile = function(file){
396
+    var fs = require('fs');
397
+    fs.unlinkSync(file);
398
+    console.log('-> Successfully Deleted ' + file);
399
+    return true;
400
+  }
401
+
395 402
 
396 403
 
397 404
   // RESPONSE
@@ -476,4 +483,8 @@ angular.module('codexApp')
476 483
     }
477 484
   }
478 485
 
486
+  this.deleteFile = function(file) {
487
+    return deleteFile(file);
488
+  }
489
+
479 490
 }])

+ 0 - 1
codex/inbox/hgvhgc.md

@@ -1 +0,0 @@
1
-gjcjgcghj